package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckedTextView;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher.ViewFactory;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity121 extends AppCompatActivity {

    private TextSwitcher switcher;
    private Button change0;
    private Button change1;

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity121.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main121 );
        initView();
    }

    private void initView() {

        switcher = (TextSwitcher) findViewById( R.id.switcher );
        switcher.setFactory( new ViewFactory() {
            @Override
            public View makeView() {

                TextView textView = new CheckedTextView( switcher.getContext() );
                textView.setTextSize( 20 );
                textView.setTextColor( getResources().getColor( R.color.black ) );
                return textView;
            }
        } );
        switcher.setCurrentText( "hello World" );

        change0 = (Button) findViewById( R.id.change0 );
        change0.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                switcher.setText( "奶酪棒" );
            }
        } );

        change1 = (Button) findViewById( R.id.change1 );
        change1.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                switcher.setText( "切片面包" );
            }
        } );
    }
}